package com.example.demo.controller;

import com.example.demo.service.IHappyLockService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author chxbca
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(path = "/happyLock")
public class TestController {

    private final IHappyLockService happyLockService;

    @GetMapping
    public Object get(@RequestParam(name = "q", required = false, defaultValue = "{}") String q,
                      @RequestParam(name = "page", required = false, defaultValue = "0") Integer page,
                      @RequestParam(name = "size", required = false, defaultValue = "5") Integer size) {
        return happyLockService.query(q, PageRequest.of(page, size));
    }

    @GetMapping("/{id}")
    public Object get(@PathVariable Integer id) {
        return happyLockService.findById(id);
    }

}